package com.hxtrip.zero.common.res;

/**
 * @author Hireek
 */
public enum ApiErrorCode implements IErrorCode {

    FAILED(-1, "操作失败"),

    SUCCESS(0, "执行成功"),

    TO_MANY_REQUEST(10003, "请求流量过大");
    private final Integer code;
    private final String msg;

    ApiErrorCode(final Integer code, final String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ApiErrorCode fromCode(long code) {
        ApiErrorCode[] ecs = ApiErrorCode.values();
        for (ApiErrorCode ec : ecs) {
            if (ec.getCode() == code) {
                return ec;
            }
        }
        return SUCCESS;
    }

    @Override
    public Integer getCode() {
        return code;
    }


    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return String.format(" ErrorCode:{code=%s, msg=%s} ", code, msg);
    }
}
